extern "C"
{
#include <winsock2.h>
}
#include "NetworkCommonFunction.h"
#include "playrealtimevideo.h"

#include <QDebug>

bool RealtimePlayHandler(int socket, int commandLength)
{
	qDebug()<<"Receive realtime play command";

	sockaddr_in groupLeaderVideoAddress;
	sockaddr_in groupLeaderAudioAddress;

	memset(&groupLeaderVideoAddress, 0, sizeof(groupLeaderVideoAddress));
	groupLeaderVideoAddress.sin_family = AF_INET;
	if(!receiveData(socket, (char*)(& groupLeaderVideoAddress.sin_addr.s_addr), 4))
	{
		qDebug()<<"Get group leader ip error";
		return false;
	}
	if(!receiveData(socket, (char*)(&groupLeaderVideoAddress.sin_port),2))
	{
		qDebug()<<"Get group leader file server port error";
		return false;
	}

	groupLeaderAudioAddress = groupLeaderVideoAddress;
	if(!receiveData(socket, (char*)(&groupLeaderAudioAddress.sin_port),2))
	{
		qDebug()<<"Get group leader audio port error";
		return false;
	}

	PlayRealtimeVideo playRealTimeVideo(groupLeaderVideoAddress, groupLeaderAudioAddress);
	playRealTimeVideo.doCommand();
	return true;
}
